package edu.mit.compilers.assembly.x64.basic;

import java.util.ArrayList;

public class X64RegisterMemOperand implements X64Operand {
    // (%baseR), like (%rax)
    private X64Register baseR;

    // offsetImm(%baseR), like -8(%rsi)
    private String offsetImm;         // optional

    public X64RegisterMemOperand(X64Register baseR, String offsetImm) {
        this.baseR = baseR;
        this.offsetImm = offsetImm;
    }

    @Override
    public String getAddress() {
        return offsetImm + "(%" + baseR.name + ")";
    }

    @Override
    public Type getType() {
        return Type.MEM;
    }

    @Override
    public ArrayList<X64Register> getUsedRegisters() {
        ArrayList<X64Register> ret = new ArrayList<>();
        ret.add(baseR);
        return ret;
    }
}
